package com.chidt.zpro.service.impl;

import cn.hutool.crypto.SecureUtil;
import com.chidt.zpro.dao.UserDao;
import com.chidt.zpro.dao.impl.UserDaoImpl;
import com.chidt.zpro.entity.User;
import com.chidt.zpro.service.UserService;

import java.sql.SQLException;

public class UserServiceImpl implements UserService {
    @Override
    public void register(User user) throws SQLException {
        System.out.println("处理注册："+user.getUsername()+" "+user.getEmail());
        //TODO: 用户注册业务逻辑
        UserDao userDao = new UserDaoImpl();
        userDao.saveUser(user);
        System.out.println("注册成功");

    }

    @Override
    public User login(String username, String password) throws SQLException {
        UserDao userDao = new UserDaoImpl();
        String md5 = SecureUtil.md5(password);
        User user = userDao.getUserByUsernameAndPassword(username,md5);
        return user;
    }
}
